package cn.szzsi.common.model;

import cn.szzsi.common.model.base.BaseTemplateUser;

import java.util.List;

/**
 * Created by yuanzheng on 2016/9/21.
 * 会员模板实体类
 */
//@TableBind(tableName = "b_template_user",pkName = "id")
public class TemplateUser extends BaseTemplateUser<TemplateUser> {
    public static final TemplateUser dao =new TemplateUser().dao();

    public static final List<TemplateUser> getByUserId(String uid){
        return dao.find("select * from mall_template_user where uid=?",uid);
    }

    public static final TemplateUser getPcTemplate(String uid){
        return dao.findFirst("select * from mall_template_user where uid=? and b_template_type='pc'",uid);
    }
    public static final TemplateUser getWapTemplate(String uid){
        return dao.findFirst("select * from mall_template_user where uid=? and b_template_type='wap'",uid);
    }

    public static final TemplateUser getByUserIdAndType(String uid, String template_type){
        return dao.findFirst("select * from mall_template_user where uid=? and b_template_type=?",uid,template_type);
    }

    public static final void saveTemplateUser(String uid, Integer b_template_id, String b_template_type){
        TemplateUser btu=new TemplateUser();
        btu.set("uid",uid);
        btu.set("b_template_id",b_template_id);
        btu.set("createtime", System.currentTimeMillis());
        btu.set("b_template_type",b_template_type);
        btu.save();
    }

    public static final void updateTemplateUser(TemplateUser btu, String uid, Integer b_template_id, String b_template_type){
        btu.set("uid",uid);
        btu.set("b_template_id",b_template_id);
        btu.set("b_template_type",b_template_type);
        btu.update();
    }


}
